package com.naja.auth2server.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @auther wangjianying
 * @date 2023/12/19 14:50
 */
@Configuration
@EnableRedisHttpSession
public class RedisHttpSessionConfig {
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
//        cookieSerializer.setDomainName("");
        cookieSerializer.setCookieName("ZTSESSION");
        return cookieSerializer;
    }

    /**
     * bean名称必须为:springSessionDefaultRedisSerializer
     *
     * @return
     */
    @Bean("springSessionDefaultRedisSerializer")
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(@Qualifier("oauth2ObjectMapper")ObjectMapper oauth2ObjectMapper) {
        return new GenericJackson2JsonRedisSerializer(oauth2ObjectMapper);
    }
}
